<?php
include '/var/www/html/new/d/module/qkxproject/api/ziwoyou/ziwoyou.class.php';
include('/var/www/html/new/d/module/api/function.class.php');
//$txt = file_get_contents($_REQUEST);
$txt =  json_encode($_REQUEST);
logfile(date('Y-m-d H:i:s').'---'.$txt ,'/var/www/html/new/d/module/qkxproject/api/ziwoyou/ziwoyou_get_data.txt');
$PFT_infunction = new AllFunction();
if (!class_exists("go_sql")) {
    include("/var/www/html/new/conf/le.je");
    $le = new go_sql();
    $le->connect();
}


$ls_order = 'pft'.str_replace('.',mt_rand(1000,9999),microtime(true));
if(!isset($_REQUEST['Action'])){
    $select_uuid = "select uuid  from uu_jq_ticket where id=" . $_REQUEST['TicketID'] . " limit 1";
    $GLOBALS['le']->query($select_uuid);
    $GLOBALS['le']->fetch_assoc();
    $uuid = $GLOBALS['le']->f('uuid');
    $request_arr =array('num'=>$_REQUEST['Tnum'],
        'link_man'=>$_REQUEST['TouristName'],
        'order_source_id'=>$_REQUEST['Ordern'],
        'link_phone'=>$_REQUEST['TouristTel'],
        'travel_date'=> date('Y-m-d',strtotime($_REQUEST['PlayDate'])),
        'info_id'=>$uuid,
        'order_source_id'=>$ls_order
    );
    $ziwoyou = new ZiWoYou();
    $response =  $ziwoyou->order($request_arr);
    if($response==101)exit("101|0|0|0|0|0");
     exit("200|0|0|0|{$response['ls_order']}|{$response['orderid']}");

}elseif($_REQUEST['Action'] == 'Relation'){

    $Ordern = $_REQUEST['Ordern'];
    $pft_order_xml = $PFT_infunction->Select_PFTorder($_REQUEST['Ordern']);
    $tnum = (int)$pft_order_xml->Rec->UUtnum;
    $apiOrder = (string)$pft_order_xml->Rec->UUtordernum;
    $tempOrder = (string)$pft_order_xml->Rec->UUvcode;
    $str="insert into all_api_order (pftOrder,apiOrder,tempOrder,coopB,oStatus,oStnum,apiCode,handleStatus,cTime) values('$Ordern','$apiOrder','$tempOrder',5,0,$tnum,'$apiOrder',0,now())";
    $GLOBALS['le']->query($str);
}elseif($_REQUEST['Action']=='MOD'){

        if($_REQUEST['Tnum'] != 0) exit("1077|0|0|0|0|0");  //没有修改的接口
        $pft_order_xml = $PFT_infunction->Select_PFTorder($_REQUEST['Ordern']);

        $UUtordernum = (string)$pft_order_xml->Rec->UUtordernum;
        $ziwoyou = new ZiWoYou();
        $orderCancel = $ziwoyou->canceOrder($UUtordernum);
        // print_r($orderCancel);exit;
        if($orderCancel == 100){
            $str="update all_api_order set oStatus=3,handleStatus=0 where pftOrder='".$_REQUEST['Ordern']."' limit 1";
            $GLOBALS['le']->query($str);
            exit("200|0|0|0|0|0");
        }
        else exit("1077|0|0|0|0|0");
}



function logfile($txt, $path)
{
    $fp = fopen($path, "a");
    flock($fp, LOCK_EX);
    fwrite($fp, $txt . "\n");
    flock($fp, LOCK_UN);
    fclose($fp);
}